<template>
  <div class="search-list" v-show="searches.length">
    <transition-group name="list" tag="ul">
      <li
        class="search-item"
        v-for="item in searches"
        :key="item"
        @click="selectItem(item)"
      >
        <span class="text">{{ item }}</span>
        <span class="icon" @click.stop="deleteOne(item)">
          <i class="icon-delete"></i>
        </span>
      </li>
    </transition-group>
  </div>
</template>

<script type="text/ecmascript-6">
export default {
  props: {
    searches: {
      type: Array,
      default() {
        return []
      }
    },
  },
  methods: {
    deleteOne(item) {
      this.$emit('delete', item)
    },
    selectItem(item) {
      this.$emit('select', item)
    }
  }
}
</script>

<style scoped lang="stylus"  ref="stylesheet/stylus">
@import '~assets/stylus/variable';
@import '~assets/stylus/mixin';

.search-list {
  .search-item {
    display: flex;
    align-items: center;
    height: 40px;
    overflow: hidden;

    .text {
      flex: 1;
      color: $color-text-l;
    }

    .icon {
      extend-click();
      text-align: center;

      .icon-delete {
        font-size: $font-size-small;
        color: $color-text-d;
      }
    }

    &.list-enter-active, &.list-leave-active {
      transition: all 0.1s;
    }

    &.list-enter, &.list-leave-to {
      height: 0;
    }
  }
}
</style>